import axios from 'axios'
import store from '@/store'
import router from '@/router'
import { message } from 'ant-design-vue';
var BASE_URL='http://139.224.164.161:9998/index.php'
var TIMEOUT=6000
var instance=axios.create({
    baseURL:BASE_URL,
    timeout:TIMEOUT
})

//请求拦截
instance.interceptors.request.use(config=>{
    if(store.state.user.token){
        config.headers.token=store.state.user.token
    }
    return config
},err=>{

})


//响应拦截
instance.interceptors.response.use(config=>{
       if(config.data.code==40001){
            message.error('Token已过期，请重新登录！')
           router.replace('/login')
       }
       else{
           if(config.data.code!=200){
               console.log(config)
            message.error(config.data.data)
           }
       }
        return config
},err=>{

})


export default function request(params){

    return instance(params)
}